package com.yun.space.pro.fileUpload.action;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import com.yun.space.base.BaseAction;
import com.yun.space.entity.User;

/**
 * 文件上传测试
 * @author guo
 *
 */
public class DemoAction extends BaseAction<User>{
	
	private File image;//文件
	private String fileName;//文件名称 
	private String fileContentType; //文件类型 
	private String savePath;//文件名
	/**
	 * @author guo
	 * @return 上传例子
	 */
	public String toUpload(){
		File dir=new File(ServletActionContext.getServletContext().getRealPath("upload")); 
		//判断文件是否上传，如果上传的话将会创建该目录 
		if(!dir.exists()){ 
			dir.mkdir(); //创建该目录 
		} 
		System.out.println(image);
		System.out.println(fileName);
		try {
			FileUtils.copyFile(image,new File(dir,fileName)); 
		} catch (IOException e) {
			e.printStackTrace();
		} 
		return "toUpload";
	}
	public File getImage() {
		return image;
	}
	public void setImage(File image) {
		this.image = image;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public String getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}
	public String getSavePath() {
		return savePath;
	}
	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}
	
}
